package org.kia.manager;

import java.util.List;

import org.kia.data.DataProxy;
import org.kia.data.DataProxy.MethodType;
import org.kia.data.interfaces.OnDataReceivedListener;
import org.kia.data.model.CategoryModel;
import org.kia.data.model.ItemModel;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;

/**
 * 
 * @author Amir Lazarovich & Keren Kalev
 */
public class ServerComManager {
	
	//////////////////////////////////////////////
	// Members
	//////////////////////////////////////////////
	private static ServerComManager sInstance;
	
	//////////////////////////////////////////////
	// Constructors & Singleton related methods
	//////////////////////////////////////////////
	
	/**
	 * Private constructor to prohibit more instances of this class
	 */
	private ServerComManager() {
		
	}
	
	/**
	 * Get the (only) instance of this class
	 * 
	 * @return
	 */
	public synchronized static ServerComManager getInstance() {
		if (sInstance == null) {
			sInstance = new ServerComManager();
		}
		
		return sInstance;
	}

	//////////////////////////////////////////////
	// Public
	//////////////////////////////////////////////
	
	/**
	 * Get all categories from the server
	 * 
	 * @param callback The callback class that will be invoked when the data is received
	 * @return 
	 */
	public AsyncTask getCategories(Context context, OnDataReceivedListener<List<CategoryModel>> callback) {
		return DataProxy.get(MethodType.CATEGORIES, context, null, callback);
	}

	/**
	 * Get all items in a category from the server
	 * 
	 * @param context
	 * @param categoryId
	 * @param callback
	 * @return
	 */
	public AsyncTask getItemsInCategory(Context context, String categoryId, OnDataReceivedListener<List<ItemModel>> callback) {
		Bundle params = new Bundle();
		params.putString("category", categoryId);
		
		// TODO getItemsInCategory:: HARD ASS MOCKING HERE
		params.putString("lat", "31.84");
		params.putString("long", "35");
		params.putString("radius", "2500");
		
		return DataProxy.get(MethodType.ITEMS_IN_CATEGORY, context, params, callback);
	}
}
